import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/views/Layout/index.vue'
import Search from '@/views/Search/index.vue'
import Home from '@/views/Home/index.vue'
import HotSearch from '@/views/Search/HotSearch.vue'
import SongList from '@/views/Search/SongList.vue'
import Play from '@/views/Play/index.vue'
import Comments from '@/views/Comment/index.vue'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/layout'
  }, {
    path: '/layout',
    redirect: '/layout/home',
    component: Layout,
    children: [{
      path: 'search',
      redirect: '/layout/search/hotsearch',
      meta: {
        title: '搜索'
      },
      component: Search,
      children: [{
        path: 'hotsearch',
        component: HotSearch
      }, {
        path: 'songlist',
        component: SongList
      }]
    }, {
      path: 'home',
      meta: {
        title: '首页'
      },
      component: Home
    }]
  }, {
    path: '/play',
    component: Play
  },
  {
    path: '/comment',
    component: Comments
  }
]

const router = new VueRouter({
  routes
})

// 请求重复路由时
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

export default router
